package com.qf.flash.ui.chat;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.hyphenate.easeui.widget.EaseTitleBar;
import com.qf.dblib.dao.entity.ChatUserBean;
import com.qf.flash.R;
import com.qf.flash.mvp.contract.NewFriendInviteContract;
import com.qf.flash.mvp.presenter.NewFriendInvitePresenter;
import com.qf.flash.utils.MyUtil;
import com.qf.flashlib.adapter.RVAdapter;
import com.qf.flashlib.base.BaseActivity;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 新的好友验证
 */
public class NewFriendsMsgActivity extends BaseActivity implements NewFriendInviteContract.View, NewFriendsItem.ReMovedOneMsg {
    @BindView(R.id.title_bar)
    EaseTitleBar titleBar;
    @BindView(R.id.list)
    RecyclerView list;

    private RVAdapter mAdapter;

    private List<Object> datas;
    private NewFriendInvitePresenter newFriendInvitePresenter;
    private NewFriendsItem newFriendsItem;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_new_friends_invite_msg;
    }

    @Override
    protected void initInject() {
        super.initInject();
        newFriendInvitePresenter = new NewFriendInvitePresenter();
        initPresenters(newFriendInvitePresenter);
    }

    @Override
    protected void initViewAndData() {
        newFriendsItem = new NewFriendsItem();
        titleBar.setLeftLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        mAdapter = new RVAdapter<>(newFriendsItem);
        list.setLayoutManager(new LinearLayoutManager(this));
        list.setAdapter(mAdapter);
        datas = mAdapter.getDatas();
        newFriendInvitePresenter.getChatUserList(1,30);
        newFriendsItem.setReMovedOneMsg(this);
    }

    public static void start(Activity activity) {
        Intent intent = new Intent(activity, NewFriendsMsgActivity.class);
        activity.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ButterKnife.bind(this);
    }

    @Override
    public void setUi(List<ChatUserBean> chatUserBeans) {
        if(MyUtil.isNullOrEmpty(chatUserBeans)){
            datas.clear();
        }else {
            datas.addAll(chatUserBeans);
        }
        mAdapter.notifyDataSetChanged();
    }

    @Override
    public void addFriendResult(boolean success) {

    }

    @Override
    public void deleteOne(int position) {
        datas.remove(position);
        mAdapter.notifyDataSetChanged();
    }

    @Override
    public void addOne(String uid) {
        newFriendInvitePresenter.receiveInvite(uid);
    }
}
